// https://leetcode.cn/problems/pascals-triangle/

#include <iostream>
#include <vector>


using namespace std;

class Solution {
public:
    vector<vector<int>> generate(int numRows) {
        vector<vector<int>> res;
        vector<int> one = {1};
        res.push_back(one);
        if (numRows == 1) {
            return res;
        }
        vector<int> two = { 1,1 };
        res.push_back(two);
        if (numRows == 2) {
            return res;
        }
        for (int i = 2; i < numRows; i++) {
            vector<int> tmp = { 1 };
            for (int j = 1; j < i; j++) {
                tmp.push_back(res[i - 1][j] + res[i - 1][j - 1]);
            }
            tmp.push_back(1);
            res.push_back(tmp);
        }
        return res;
    }

    void show(vector <vector<int>>& grid) {
        for (auto items : grid) {
            for (auto i : items) {
                cout << i << ",";
            }
            cout << endl;
        }
    }
};

int main() {
    Solution so;
    int n = 4;
    auto items = so.generate(n);
    cout << "n:" << n << endl;
    so.show(items);
    return 0;

}

